package bgg4j;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class GameInfo extends Game {

	public GameInfo(Element elem, Bgg bgg) throws BggException {
		super(elem, bgg);
		// TODO 自動生成されたコンストラクター・スタブ
	}

	public String getName(){
		return this.getChildText("name");
	}
	
	public String getDesigner(){
		return this.getChildText("designer",true);
	}
	
	public int getYear(){
		return Integer.valueOf(this.getChildText("yearpublished"));
	}
	
	public int getMinPlayer(){
		return Integer.valueOf(this.getChildText("minplayers"));
	}
	
	public int getMaxPlayer(){
		return Integer.valueOf(this.getChildText("maxplayers"));
	}
	
	public int getPlayingTime(){
		return Integer.valueOf(this.getChildText("playingtime"));
	}
	
	public String getDescription(){
		return this.getChildText("description");
	}
	
	public int getRank(){
		if (this.getChildText("rank") == null){
		return -1;	
		}else{
		return Integer.valueOf(this.getChildText("rank"));
		}
	}
	
	public float getBayesAverage(){
		if (this.getChildText("bayesaverage") == null){
		return 0;	
		}else{
		return Float.valueOf(this.getChildText("bayesaverage"));
		}
	}
	
	public 
    /*package*/ static List<GameInfo> constructGameInfo(Document doc,
            Bgg bgg) throws BggException{
            if (null == doc) {
                return new ArrayList<GameInfo> (0);
            } else {
                try {
                    ensureRootNodeNameIs("games", doc.getDocumentElement());
                    NodeList list = doc.getDocumentElement().getElementsByTagName(
                            "game");
                    int size = list.getLength();
                    List<GameInfo> statuses = new ArrayList<GameInfo>(size);
                    for (int i = 0; i < size; i++) {
                        Element status = (Element) list.item(i);
                        statuses.add(new GameInfo(status, bgg));
                    }
                    return statuses;
                } catch (BggException te) {
                    return new ArrayList<GameInfo>(0);
                }
            }
        }
}